(function(){
	function sideItem(){
		this.currentTarget = null;
		this.hasOpen = false;
		this.sidebar = document.getElementById('js_sidebar');
		this.items = this.sidebar.getElementsByTagName('li');

		var self = this;
		for(var i = 0; i < this.items.length; i++){
			this.items[i].addEventListener('click',function(){
				self.show(this);
			})
		}
	}

	sideItem.prototype = {
		show: function(target){
			var content = document.getElementById(target.id + '_content');
			if(this.currentTarget){
				if(this.currentTarget !== content){
					this.removeClass(this.currentTarget,'content_move_right');
					this.removeClass(this.currentTarget,'content_move_up');
					this.currentTarget.classList.add('content_move_left');
					this.removeClass(content,'content_move_left');
					content.classList.add('content_move_up');
				}
			}else{
				content.classList.add('content_move_right');
				this.hasOpen = true;
			}
			this.currentTarget = content;
			console.log('show' + ' ' + target.id);
		},
		hide: function(target){
			if(this.currentTarget){	
			this.removeClass(this.currentTarget,'content_move_right');
					this.removeClass(this.currentTarget,'content_move_up');
					this.currentTarget.classList.add('content_move_left');
					var item_content = [];
					for(var i = 0; i < this.items.length; i++){
						item_content[i] = document.getElementById(this.items[i].id + '_content');
						this.removeClass(item_content[i],'content_move_left');
						console.log(this.items[i]);
					}
			}
		},
		hasClass: function( elements,cName ){ 
			return !!elements.className.match( new RegExp( "(\\s|^)" + cName + "(\\s|$)") ); 
		},
		removeClass: function( elements,cName ){ 
			if( this.hasClass( elements,cName ) ){ 
				elements.className = elements.className.replace( new RegExp( "(\\s|^)" + cName + "(\\s|$)" )," " ); 
			}
		}
	}

	function sidebar(){
		this.isOpen = true;
		var sidebar = document.getElementById('js_sidebar'),
			btnClose = document.getElementById('btnClose'),
			self = this;
		btnClose.addEventListener('click',function(e){
			if(self.isOpen){
				if(item.hasOpen){
					item.hide();
				}
				self.hide(sidebar,btnClose);
			}else{
				self.show(sidebar,btnClose);
			}
		});
	}

	sidebar.prototype = {
		show: function(sidebar,btnClose){
			sidebar.classList.add('sidebar_move_right');
			this.removeClass(sidebar,'sidebar_move_left');
			btnClose.classList.add('close_move_left');
			this.removeClass(btnClose,'close_move_right');
			this.isOpen = true;
		},
		hide: function(sidebar,btnClose){
			item.hide(item.currentTarget);
			item.currentTarget = null;
			sidebar.classList.add('sidebar_move_left');
			this.removeClass(sidebar,'sidebar_move_right');
			btnClose.classList.add('close_move_right');
			this.removeClass(btnClose,'close_move_left');
			this.isOpen = false;
		},
		hasClass: function( elements,cName ){ 
			return !!elements.className.match( new RegExp( "(\\s|^)" + cName + "(\\s|$)") ); 
		},
		removeClass: function( elements,cName ){ 
			if( this.hasClass( elements,cName ) ){ 
				elements.className = elements.className.replace( new RegExp( "(\\s|^)" + cName + "(\\s|$)" )," " ); 
			}
		}
	}
	var side = new sidebar();
		item = new sideItem();
	
})();